// @Date         2021-11-12
// @Author       Aaron Zhang
// @Description
// @FileName      util.go

package util

import (
	"encoding/json"
	"os"
	"strings"
)

func InArray(arr []string, search string) bool {
	for _, v := range arr {
		if search == v {
			return true
		}
	}
	return false
}
func Struct2Map(obj interface{}, target interface{}) error {
	data, err := json.Marshal(obj)
	if err != nil {
		return err
	}
	return json.Unmarshal(data, target)
}

func StrFirstToUpper(str string) string {
	return strings.ToUpper(str[:1]) + str[1:]
}

func PathExists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}

	if os.IsNotExist(err) {
		return false, nil
	}

	return false, err
}
